import axios from 'axios';

export default (url, data, method = 'get') => {
  const dataField = method === 'get' ? 'params' : 'data';
  return new Promise((resolve, reject) => {
    axios({
      method,
      url,
      [dataField]: data
    }).then(res => {
      const result = res.data;
      if (result.code === 0) {
        resolve(result.data);
      } else {
        reject(result.message);
      }
    }).catch(e => {
      reject(e);
    });
  });
}
